﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;

using DDay.iCal;

public partial class Tourism: System.Web.UI.Page
{
    protected string sMainNewsSubTitle = string.Empty;
    protected string sMainArticleImage = string.Empty;
    protected string sMainArticleLink = string.Empty;
    protected string sMainArticleTitle = string.Empty;

    protected ArticleItem DeadSeaArticle;
    CalEvents calendar;
    
    protected string sDiagOutput;
    protected string sHotelsOutput;

    protected void Page_Load(object sender, EventArgs e)
    {
        calendar = new CalEvents();

        Calendar1.TodaysDate= DateTime.Today;
        Calendar1.UseAccessibleHeader = false;

        HtmlMeta meta = new HtmlMeta();

        meta.Name = "keywords";
        meta.Content = PageHeaderData.GetPageKeywordsByType(NewsType.MedicalTourism);
        this.Header.Controls.Add(meta);

        // Hightlight main menu
        ucHeader1.index = "6";

        if (!IsPostBack)
        {
            //GetNews
            DataTable DT = Dal.ExecuteDBsp("usp_GetTourismPage");
            if (DT != null)
                if (DT.Rows.Count > 0)
                {
                    sMainArticleTitle = DT.Rows[0]["title"].ToString();
                    sMainNewsSubTitle = DT.Rows[0]["subtitle"].ToString();
                    sMainArticleImage = (DT.Rows[0]["img439x217"].ToString().Length > 0) ? DT.Rows[0]["img439x217"].ToString() : "630x200.jpg";
                    sMainArticleLink = DT.Rows[0]["cPageName"].ToString();

                    DataTable DTotherNews = new DataTable();

                    DTotherNews = DT.Clone();
                    for (int iCount = 1; iCount < DT.Rows.Count; iCount++)
                    {
                        DTotherNews.NewRow();
                        DataRow dr = DTotherNews.NewRow();
                        dr.ItemArray = DT.Rows[iCount].ItemArray;
                        DTotherNews.Rows.Add(dr);
                    }

                    dlNews.DataSource = DTotherNews;
                    dlNews.DataBind();
                }
            DataTable DTHotels = Dal.ExecuteDBsp("usp_GetTopHotels");
            foreach (DataRow Item in DTHotels.Rows)
            {
                sHotelsOutput += string.Format("<li><a href='{0}-h.aspx'>{1}</a></li>", HttpUtility.UrlEncode(Item["cpageName"].ToString()), Item["cTitle"].ToString());
            }
            //rptHotels.DataBind();
            // Get DeadSeaInfo
            DeadSeaArticle = Articles.GetArticleCatID((int)NewsType.deadSea); // Lechenie na mertvom more

            //Diagnostic
            List<CategoryItem> CatList = Category.ByAncestors((int)NewsType.Diagnostic);
            CatList.RemoveAt(0);

            foreach (CategoryItem Item in CatList)
            {
                sDiagOutput += string.Format("<li><a href='{0}.aspx'>{1}</a></li>", HttpUtility.UrlEncode(Item.cPageName), Item.cTitle);
            }
        }
        ScriptManager.RegisterClientScriptBlock(Calendar1, Calendar1.GetType(), "Calendar", "InitCalendar();",true);
    }

    protected void Calendar_OnDayRender(Object sender, System.Web.UI.WebControls.DayRenderEventArgs e)
    {
        List<CalEvent> lstEvents=calendar.findEvents(e.Day.Date);
        if (lstEvents.Count>0)
        {
            e.Cell.CssClass = "date_has_event";
            
            if (e.Day.IsOtherMonth)
            {
                e.Cell.CssClass = "OtherMonth_event";
            }
            if (e.Day.IsWeekend)
            {
                e.Cell.CssClass = "Weekend_has_event";
            }
            if (e.Day.IsToday)
            {
                e.Cell.CssClass = "today_event";
            }

            LiteralControl lc = new LiteralControl();
            string sEvent = "<div class=\"events\"><ul>";

            foreach (CalEvent item in lstEvents)
            {
                sEvent +=string.Format("<li><span class=\"title\">{0}</span> <span class=\"desc\">{1}</span> </li>", item.Summary, item.Description);
            }
            sEvent +="</ul></div>";
            lc.Text = sEvent;
            e.Cell.Controls.Add(lc);
        }
    }
}
